package com.vinci.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Hashtable;

import com.mysql.jdbc.Statement;
import com.vinci.beans.Enseignant;
import com.vinci.beans.Index;


public class IndexModel extends ModelDAO{
	

	Connection connection =null;
	ResultSet rs = null; 
	Hashtable<String,String> maListe;

	
	
	private String HARPEGE;
	private String PASSWORD;
	
	

	  public Hashtable<String,String> listeEnseignant(){
	        Hashtable<String,String> listEnseignant= new Hashtable<String,String>();
	        
	        Index index = null;
	        
	        try{
	            
	            Statement st = (Statement) cx.createStatement();
	            ResultSet rs = st.executeQuery("SELECT harpege, password FROM enseignant");
	            System.out.println(" ok 1");
	            if (rs!=null){
	            	 System.out.println(rs.getString(0));
	            	 while(rs.next())
	 	            {
	 	            	index = mapperConnection(rs);
	 	                listEnseignant.put(rs.getString("harpege"),rs.getString("password"));
	 	                 
	 	            }
	            	
	            }
	          
	            
	            
	            rs.close();
	            st.close();
	            System.out.println(" ok 2");
	        }
	        catch(SQLException ex){
	            System.err.println(":/ Probleme requete SQL des enseignants.");
	            System.exit(1);
	        }
	        
	        return listEnseignant;
	    }
	  
	  public Index mapperConnection(ResultSet resultSet){
			Index iconnection = new Index();

			try
			{
				if(resultSet.getString("HARPEGE")==null){
					iconnection.setHARPEGE("000");
				}
				else
				{
					iconnection.setHARPEGE(resultSet.getString("HARPEGE"));
				}

				if(resultSet.getString("PASSWORD")==null){
					iconnection.setPASSWORD("Anonyme");
				}
				else
				{
					iconnection.setPASSWORD(resultSet.getString("PASSWORD"));
				}


			}catch(Exception ex)
			{
				iconnection = null;
				System.out.println("Erreur lors du mapping des attributs"+ex);
			}
			return iconnection;
		}

	public String getHARPEGE() {
		return HARPEGE;
	}

	public void setHARPEGE(String hARPEGE) {
		HARPEGE = hARPEGE;
	}

	public String getPASSWORD() {
		return PASSWORD;
	}

	public void setPASSWORD(String pASSWORD) {
		PASSWORD = pASSWORD;
	}



	  
	  
}
